import Vue from 'vue';
import Main from './main.vue';

let MessageConstructor = Vue.extend(Main);

let instance;

const openMenu = function(e,list) {

  // 防止空数组
  if(!list || !list.array || list.array.length <= 0){
      return
  }
  // 防止没有text   j为空text数量
  let j = 0
  for(let i = 0;i < list.array.length;i ++){
    if(!list.array[i].text){
      j ++
    }
  }
  if(j >= list.array.length){
    return
  }

  if(!instance){
    instance = new MessageConstructor();
    instance.vm = instance.$mount();
  }

  document.body.appendChild(instance.vm.$el);

  // 传入事件
  instance.vm.e = e
  instance.vm.list = list

  // 显示
  instance.vm.show = true;
  
  // 获取don节点
  instance.dom = instance.vm.$el;

  // intit
  instance.vm.init()
  
  return instance.vm;
};

export default openMenu;
